package com.cml.domain.factory;

import com.cml.domain.entity.Message;
import com.cml.domain.entity.VoteMessage;

import java.io.DataInputStream;
import java.io.IOException;
import java.nio.ByteBuffer;

/**
 * 姓名：陈茂林
 * 时间：2023/10/11 9:08
 * 描述：
 */
public class VoteMessageBuilderFactory extends  MessageBuilderFactory{



    @Override
    public Message doBuildMessage(DataInputStream dataInputStream) throws IOException {
        VoteMessage voteMessage = new VoteMessage();
        voteMessage.setVoteNumber(dataInputStream.readInt());
        voteMessage.setVoteCount(dataInputStream.readInt());
        voteMessage.setVoteNodeId(dataInputStream.readInt());
        return voteMessage;
    }

    @Override
    public void doMessageBuilder(ByteBuffer byteBuffer, Message message) throws IOException {
        VoteMessage voteMessage = (VoteMessage) message;
        byteBuffer.putInt(voteMessage.getVoteNumber());
        byteBuffer.putInt(voteMessage.getVoteCount());
        byteBuffer.putInt(voteMessage.getVoteNodeId());
    }


}
